import type { LoadingOptions } from 'element-plus'
import { ElLoading } from 'element-plus'

export interface LoadingParentElement extends HTMLElement {
  vLoadingAddClassList?: () => void
}

let loading: ReturnType<typeof ElLoading.service> | undefined

/**
 * 打开加载提示
 * @param options - ToastOptions
 * @returns ToastWrapperInstance实例对象
 */
export function openLoading(options: LoadingOptions = {}) {
  loading = ElLoading.service({
    lock: true,
    text: '加载中...',
    ...options,
  })
  return loading
}

/**
 * 关闭加载提示
 */
export function closeLoading() {
  loading?.close()
  loading = undefined
}
